package fr.lille.inria.adam.lifl.EcoGardeInventory.Utils;

import android.location.Location;
import android.os.Parcel;
import android.os.Parcelable;
import fr.lille.inria.adam.lifl.EcoGardeInventory.R;

public class SIGObservation implements Parcelable {
	public static final int QT_CONTENT_FIELD = 12;
	public int observateur = -1;
	public int recensement = -1;
	public int groupeEspece = -1;
	public int nomEspece = -1;
	public int populationSize = -1;
	public int populationSizePrecision = -1;
	public enum Gender {
		Undefined("NR",R.string.select_population_genres_undefined), 
		Both("MF",R.string.select_population_genres_both), 
		Male("M",R.string.select_population_genres_male), 
		Female("F",R.string.select_population_genres_female);
		
		public final String code; //Identifiant du genre (M,F)
		public final int ressourceId; // Identifiant du littéral (Masculin, Féminin)
		Gender(String code, int res) {this.code=code; this.ressourceId=res;}
		public static Gender codeToGender(String code) {
			for (Gender g : Gender.values()) if (g.code.equals(code)) return g;
			return null;
		}
	}
	public Gender populationGender = Gender.Undefined;
	public int comportement = -1;
	public Location location = new Location("dummy");
	public String noteTextuelle = "";
	public String photoUri = "";
	public long timestamp;

	public static final Parcelable.Creator<SIGObservation> CREATOR = new Parcelable.Creator<SIGObservation>() {
		@Override
		public SIGObservation createFromParcel(Parcel source) {
			SIGObservation result = new SIGObservation();
			result.observateur = source.readInt();
			result.recensement = source.readInt();
			result.groupeEspece = source.readInt();
			result.nomEspece = source.readInt();
			result.populationSize = source.readInt();
			result.populationSizePrecision = source.readInt();
			result.populationGender = Gender.codeToGender(source.readString());
			result.comportement = source.readInt();
			result.location = source.readParcelable(Location.class.getClassLoader());
			result.noteTextuelle = source.readString();
			result.timestamp = source.readLong();
			result.photoUri = source.readString();
			
			return result;
		}

		@Override
		public SIGObservation[] newArray(int size) { return new SIGObservation[size]; }
	};
	
	@Override
	public int describeContents() { return 0; }

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		dest.writeInt(observateur);
		dest.writeInt(recensement);
		dest.writeInt(groupeEspece);
		dest.writeInt(nomEspece);
		dest.writeInt(populationSize);
		dest.writeInt(populationSizePrecision);
		dest.writeString(populationGender.code);
		dest.writeInt(comportement);
		dest.writeParcelable(location, flags);
		dest.writeString(noteTextuelle);
		dest.writeLong(timestamp);
		dest.writeString(photoUri);
	}

	@Override
	public String toString() {
		return "SIGObservation [observateur=" + observateur + ", recensement="
				+ recensement + ", groupeEspece=" + groupeEspece
				+ ", nomEspece=" + nomEspece + ", populationSize="
				+ populationSize + ", populationSizePrecision="
				+ populationSizePrecision + ", populationGender="
				+ populationGender + ", comportement=" + comportement
				+ ", location=" + location + ", noteTextuelle=" + noteTextuelle
				+ ", photoUri=" + photoUri + ", timestamp=" + timestamp + "]";
	}
}
